{% from 'include/input_macros.html' import input, select, checkbox %}
{% from 'include/provisioning/variables.html' import do_regions, do_oss  %}
{% for s in server %}
{% set region_name = [] %}
<div id="do_edit" style="display: none; padding: 0 2px 0 0; margin-left: 1px; margin-right: -4px;">
    <table class="overview provisioning_table">
        {% include 'include/tr_validate_tips.html' %}
        <tr>
            <td colspan="2" class="headers">
                <b>General information</b>
            </td>
        </tr>
        <tr>
            <td class="padding20">
                Server name
            </td>
            <td>
                <span id="do_edit_server_name">{{s.name}}</span>
            </td>
        </tr>
            {{input('do_edit_group', value=s.group_id, type='hidden')}}
            {{input('do_edit_id', value=s.id, type='hidden')}}
        <tr>
            <td class="padding20">
                Provider credentials
                <span class="need-field">*</span>
            </td>
            <td>
                <select id="do_edit_id_provider">
                {% for p in providers %}
                    {% if p.2 == 'do' %}
                        {% if s.provider_id|int() == p.0|int() %}
                        <option value="{{ p.0 }}" selected>{{ p.1 }}</option>
                        {% else %}
                        <option value="{{ p.0 }}">{{ p.1 }}</option>
                        {% endif %}
                    {% endif %}
                {% endfor %}
                </select>
            </td>
        </tr>
        <tr>
            <td class="padding20 padding-top20">
                Region
            </td>
            <td>
                {% for key, value in do_regions.items() %}
                {% if s.region|int() == key|int() %}
                    {% do region_name.append(value) %}
                {% endif %}
                {% endfor %}
                <span id="do_edit_regions" style="display: none;">{{s.region}}</span>
                {{region_name.0}}
            </td>
        </tr>
        <tr>
            <td colspan="2" class="headers">
                <b>Instance</b>
            </td>
        </tr>
        <tr>
            <td class="padding20">
                Size
                <span class="need-field">*</span>
            </td>
            <td>{{input('do_edit_size', size='30', value=s.instance_type)}}</td>
        </tr>
        <tr>
            <td class="padding20">
                OS
                <span class="need-field">*</span>
            </td>
            <td>
                {{ select('do_edit_oss', values=do_oss, first=s.os, disabled='false') }}
            </td>
        </tr>
        <tr>
            <td class="padding20">
                SSH
                <span class="need-field">*</span>
            </td>
            <td>
                <select id="do_edit_ssh_choose">
                    {% if s.ssh_key_name is not none %}
                    <option value="ssh_name" selected>Set SSH key name</option>
                    {% else %}
                    <option value="ssh_name">Set SSH key name</option>
                    {% endif %}
                    {% if s.ssh_ids is not none %}
                    <option value="ssh_ids" selected>Set SSH key ids</option>
                    {% else %}
                    <option value="ssh_ids">Set SSH key ids</option>
                    {% endif %}
                </select>
            </td>
        </tr>
        <tr id="do_edit_ssh_ids_tr" {% if s.ssh_ids is none %}style="display: none;"{% endif %}>
            <td class="padding20 padding-top20">
                SSH key ids
                <span class="need-field">*</span>
            </td>
            <td>
                {{input('do_edit_ssh_ids', size='30', value=s.ssh_ids)}}
                <div class="tooltip tooltipTop tooltipTd">List comma separated. Required if SSH key name is empty</div>
            </td>
        </tr>
        <tr id="do_edit_ssh_name_tr" {% if s.ssh_key_name is none %}style="display: none;"{% endif %}>
            <td class="padding20 padding-top20">
                SSH key name
                <span class="need-field">*</span>
            </td>
            <td>
                {{input('do_edit_ssh_name', size='30', value=s.ssh_key_name)}}
                <div class="tooltip tooltipTop tooltipTd">Required if SSH key ids is empty</div>
            </td>
        </tr>
        <tr>
            {% set checked='checked' %}
            {% if s.monitoring == 'false' %}
                {% set checked='' %}
            {% endif %}
            <td class="padding20">Monitoring</td>
            <td>
                {{checkbox('do_edit_monitoring', checked=checked)}}
            </td>
        </tr>
        <tr>
            {% set checked='checked' %}
            {% if s.backup == 'false' %}
                {% set checked='' %}
            {% endif %}
            <td class="padding20">Backup</td>
            <td>
                {{checkbox('do_edit_backup', checked=checked)}}
            </td>
        </tr>
        <tr>
            <td colspan="2" class="headers">
                <b>Network</b>
            </td>
        </tr>
        <tr>
            {% set checked='checked' %}
            {% if s.private_networking == 'false' %}
                {% set checked='' %}
            {% endif %}
            <td class="padding20">Private IP</td>
            <td>
                {{checkbox('do_edit_private_networking', checked=checked)}}
            </td>
        </tr>
        <tr>
            {% set checked='checked' %}
            {% if s.floating_ip == 'false' %}
                {% set checked='' %}
            {% endif %}
            <td class="padding20">Floating Ip</td>
            <td>
                {{checkbox('do_edit_floating_ip', checked=checked)}}
            </td>
        </tr>
        <tr>
            {% set checked='checked' %}
            {% if s.firewall == 'false' %}
                {% set checked='' %}
            {% endif %}
            <td class="padding20" style="padding-bottom: 25px;padding-top: 25px;">Firewall</td>
            <td>
                {{checkbox('do_edit_firewall', checked=checked)}}
                <div class="tooltip tooltipTop tooltipTd">Roxy-WI will create Security group and open 22, 443, 1999, 8085, 8086 ports. Otherwise all ports will be closed</div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <p class="validateTips alert alert-warning">Be aware: some changes may cause server re-creation. And all your data will be lost</p>
            </td>
        </tr>
    </table>
    <script>
    $( function() {
        $('#do_edit_ssh_choose').on('selectmenuchange', function (){
            if ($('#do_edit_ssh_choose option:selected').val() == 'ssh_name') {
                $('#do_edit_ssh_name_tr').show();
                $('#do_edit_ssh_ids_tr').hide();
            } else if ($('#do_edit_ssh_choose option:selected').val() == 'ssh_ids') {
                $('#do_edit_ssh_name_tr').hide();
                $('#do_edit_ssh_ids_tr').show();
            }
        });
    });
    </script>
</div>
{% endfor %}